﻿using System;
using MessagePack.Formatters;
using UnityEngine;

namespace MessagePack.Unity
{
	// Token: 0x0200012F RID: 303
	public sealed class Vector2Formatter : IMessagePackFormatter<Vector2>
	{
		// Token: 0x06000487 RID: 1159 RVA: 0x00013B30 File Offset: 0x00011F30
		public int Serialize(ref byte[] bytes, int offset, Vector2 value, IFormatterResolver formatterResolver)
		{
			int num = offset;
			offset += MessagePackBinary.WriteFixedArrayHeaderUnsafe(ref bytes, offset, 2);
			offset += MessagePackBinary.WriteSingle(ref bytes, offset, value.x);
			offset += MessagePackBinary.WriteSingle(ref bytes, offset, value.y);
			return offset - num;
		}

		// Token: 0x06000488 RID: 1160 RVA: 0x00013B74 File Offset: 0x00011F74
		public Vector2 Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
		{
			if (MessagePackBinary.IsNil(bytes, offset))
			{
				throw new InvalidOperationException("typecode is null, struct not supported");
			}
			int num = offset;
			int num2 = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);
			offset += readSize;
			float x = 0f;
			float y = 0f;
			for (int i = 0; i < num2; i++)
			{
				int num3 = i;
				if (num3 != 0)
				{
					if (num3 != 1)
					{
						readSize = MessagePackBinary.ReadNextBlock(bytes, offset);
					}
					else
					{
						y = MessagePackBinary.ReadSingle(bytes, offset, out readSize);
					}
				}
				else
				{
					x = MessagePackBinary.ReadSingle(bytes, offset, out readSize);
				}
				offset += readSize;
			}
			readSize = offset - num;
			Vector2 result = new Vector2(x, y);
			return result;
		}
	}
}
